package model;

import java.awt.Dimension;
import java.awt.Point;

public class Bearing {

	private Point myPoint;
	private double myDirection;

	// absolute directions, with north at 0
	static final int CIRCLE = 360;
	public static final int NORTH = 90;
	public static final int SOUTH = 270;
	public static final int EAST = 0;
	public static final int WEST = 180;

	public Bearing() {
		this(new Point(), NORTH);
	}

	public Bearing(Bearing oldBearing) {
		this(oldBearing.getPoint(), oldBearing.getDirection());
	}

	public Bearing(Point point, double direction) {
		myPoint = new Point(point);
		myDirection = direction;
	}

	public void setX(int x) {
		myPoint.x = x;
	}

	public void setY(int y) {
		myPoint.y = y;
	}

	public void setPoint(Point point) {
		myPoint = new Point(point);
	}

	public Point getPoint() {
		return myPoint;
	}

	public void setDirection(double direction) {
		myDirection = direction;
	}

	public int getX() {
		return myPoint.x;
	}

	public int getY() {
		return myPoint.y;
	}

	public double getDirection() {
		return myDirection;
	}

	public void translateToPoint(int n) {

		double radians = getDirectionAsRadians();
		myPoint = new Point((int) (getX() + n * Math.cos(radians)),
				(int) (getY() - n * Math.sin(radians)));
	}

	public boolean isValid(Bearing possible, Dimension myBounds) {
		if (possible.myPoint.x < 0 || possible.myPoint.x > myBounds.width
				|| possible.myPoint.y < 0
				|| possible.myPoint.y > myBounds.height)
			return false;
		else
			return true;
	}

	public double getDirectionAsRadians() {
		return myDirection * (Math.PI / 180);
	}

	/*
	 * correct bearing and path when you hit a wall
	 * 
	 * 
	 * =Get total distance "point"/vector =using location and direction, see
	 * which one touches wall first =have warp through that wall first =repeat
	 * until in bounds
	 * 
	 * public Bearing fixBearing(Bearing nextBearing, Dimension myBounds) { int
	 * xLeftOver = 0; int yLeftOver = 0;
	 * 
	 * if(isValid(nextBearing, myBounds)) return nextBearing;
	 * 
	 * Bearing enterWall = new Bearing(nextBearing); Bearing exitWall = new
	 * Bearing(nextBearing);
	 * 
	 * if(nextBearing.myPoint.x < 0){ xLeftOver =
	 * Math.abs(nextBearing.myPoint.x); enterWall.setX(0);
	 * exitWall.setX(myBounds.width); } else if(nextBearing.myPoint.x >
	 * myBounds.width){ xLeftOver = nextBearing.myPoint.x - myBounds.width;
	 * enterWall.setX(myBounds.width); exitWall.setX(0); }
	 * 
	 * else if(nextBearing.myPoint.y < 0){ yLeftOver =
	 * Math.abs(nextBearing.myPoint.y); enterWall.setY(0);
	 * exitWall.setY(myBounds.height); } else if(nextBearing.myPoint.y >
	 * myBounds.height){ yLeftOver = nextBearing.myPoint.y - myBounds.height;
	 * enterWall.setY(myBounds.height); exitWall.setY(0); }
	 * 
	 * return fixBearing(new Bearing(new
	 * Point(xLeftOver,yLeftOver),nextBearing.myDirection),myBounds); }
	 */

}